package com.lrkj.property.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.property.domain.AdvertManag;
import com.lrkj.property.service.IAdvertManagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告管理Controller
 *
 * @author yajun_ren
 * @date 2022-03-16
 */
@RestController
@RequestMapping("/property/advertManag")
@Api(tags = "广告管理")
public class AdvertManagController extends BaseController {
    @Autowired
    private IAdvertManagService advertManagService;

    /**
     * 查询广告管理列表
     */
    @ApiOperation(value = "查询广告管理列表", notes = "查询广告管理列表")
    @PreAuthorize("@ss.hasPermi('property:advertManag:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvertManag advertManag) {
        startPage();
        this.changeParameter(advertManag.getParams());
        List<AdvertManag> list = advertManagService.selectAdvertManagList(advertManag);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @ApiOperation(value = "导出广告管理列表", notes = "导出广告管理列表")
    @PreAuthorize("@ss.hasPermi('property:advertManag:export')")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdvertManag advertManag) {
        List<AdvertManag> list = advertManagService.selectAdvertManagList(advertManag);
        ExcelUtil<AdvertManag> util = new ExcelUtil<AdvertManag>(AdvertManag.class);
        return util.exportExcel(list, "广告管理数据");
    }

    /**
     * 获取广告管理详细信息
     */
    @ApiOperation(value = "获取广告管理详细信息", notes = "获取广告管理详细信息")
    @PreAuthorize("@ss.hasPermi('property:advertManag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(advertManagService.selectAdvertManagById(id));
    }

    /**
     * 新增广告管理
     */
    @ApiOperation(value = "新增广告管理", notes = "新增广告管理")
    @PreAuthorize("@ss.hasPermi('property:advertManag:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvertManag advertManag) {
        return toAjax(advertManagService.insertAdvertManag(advertManag));
    }

    /**
     * 修改广告管理
     */
    @ApiOperation(value = "修改广告管理", notes = "修改广告管理")
    @PreAuthorize("@ss.hasPermi('property:advertManag:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvertManag advertManag) {
        return toAjax(advertManagService.updateAdvertManag(advertManag));
    }

    /**
     * 删除广告管理
     */
    @ApiOperation(value = "删除广告管理", notes = "删除广告管理")
    @PreAuthorize("@ss.hasPermi('property:advertManag:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(advertManagService.deleteAdvertManagByIds(ids));
    }

    /**
     * 通过场地ID,获取广告位数量和使用情况
     */
    @ApiOperation(value = "通过场地ID,获取广告位数量和使用情况", notes = "通过场地ID,获取广告位数量和使用情况")
    @GetMapping(value = "/getAdvertPostInfo/{adverId}")
    public AjaxResult getAdvertPostInfo(@PathVariable("adverId") String adverId) {
        return AjaxResult.success(advertManagService.getAdverPostInfo(adverId));
    }
}
